package com.tianji.aigc.controller;

import com.tianji.aigc.dto.ChatDTO;
import com.tianji.aigc.service.IChatService;
import com.tianji.aigc.vo.ChatEventVO;
import com.tianji.common.annotations.NoWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/chat")
public class ChatController {
    @Autowired
    private IChatService chatService;

    /**
     * 流式对话接口
     * @param dto
     * @return
     */
    @NoWrapper//标记结果不进行包装
    @PostMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE)//指定返回text/event-stream类型,实现流式输出
    public Flux<ChatEventVO> chat(@RequestBody ChatDTO dto) {
        return chatService.chat(dto);
    }

    /**
     * 停止会话
     * @param sessionId
     */
    @PostMapping("/stop")
    public void stop(String sessionId){
         chatService.stop(sessionId);
    }
}
